package com.binyouwei.designpatterns.behavior.command;

/**
 * @author 宾有为
 * Created on 2024/7/15 22:51
 * Social homepage: https://blog.csdn.net/baidu_41616022
 * @desc 命令模式 - 将一个请求封装为一个对象，从而使你可以用不同的请求对客户进行参数化，对请求排队或记录请求日志，以及支持可撤销的操作。
 **/
public class CommandMain {
    public static void main(String[] args) {
        LightReceiver light = new LightReceiver();
        RemoteControl remoteControl = new RemoteControl();
        Command lightOn = new LightOnCommand(light);
        Command lightOff = new LightOffCommand(light);

        remoteControl.setCommand(lightOn);
        remoteControl.buttonWasPressed();
        remoteControl.buttonWasReleased();

        remoteControl.setCommand(lightOff);
        remoteControl.buttonWasPressed();
        remoteControl.buttonWasReleased();
    }
}
